/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uk.ac.cam.can.generalisator;

import java.util.Random;

/**
 *
 * @author Thomas
 */
public class GenDate implements Generalisator{
    @Override
    public String gen(String value){
        int pos = value.lastIndexOf("-");
        if(pos==-1)
            return "*";
        return value.substring(0, pos);
    }

    @Override
    public int getMaxGeneralisation() {
        return 4;
    }

    @Override
    public double getLength(String value) {
        if(value.equals("*"))
            return 4.0;
        String[] splits = value.split("-");
        if(splits.length==3)
            return 1.0;
        if(splits.length==2)
            return 2.0;
        return 3.0;
    }

    @Override
    public double getMaxLength() {
        return 4.0;
    }

    @Override
    public String getUngeneralisation(String value) {
        Random rand = new Random(System.nanoTime());
        if(value.equals("*"))
            return rand.nextInt(11)+2000+"";
        String[] splits = value.split("-");
        if(splits.length==3)
            return value;
        if(splits.length==2)
            return value+"-"+rand.nextInt(30);
        return value+"-"+rand.nextInt(13);
    }

    @Override
    public int getGeneralisationLevel(String value) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
